package utils.map;

/**
 * (必填，请用一句话描述此类型表示什么).
 * </p>
 * (可填，此类型设计的详细描述).
 *
 * @see (可填，引用或参考其他类型资源，如: {@link java.util.Properties}).
 * @author zhangbo
 * @since 1.0.0
 */
public class DateLimitKey implements Limit {

    private long startDateTimemills;
    private long surviveTimemills;

    public DateLimitKey(long surviveTimemills) {
        super();
        if (surviveTimemills <= 0) {
            return;
        }
        this.startDateTimemills = System.currentTimeMillis();
        this.surviveTimemills = surviveTimemills;
    }

    @Override
    public boolean isExpired() {
        long currentTimemills = System.currentTimeMillis();
        if (startDateTimemills + surviveTimemills <= currentTimemills) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public void expire() {
        surviveTimemills = 0;
    }

    @Override
    public void renew() {
        startDateTimemills = System.currentTimeMillis();
    }

    @Override
    public Limit copy() {
        return new DateLimitKey(surviveTimemills);
    }

    public long getStartDateTimemills() {
        return startDateTimemills;
    }

    public void setStartDateTimemills(long startDateTimemills) {
        this.startDateTimemills = startDateTimemills;
    }

    public long getSurviveTimemills() {
        return surviveTimemills;
    }

    public void setSurviveTimemills(long surviveTimemills) {
        this.surviveTimemills = surviveTimemills;
    }

    @Override
    public void use() {
        return;
    }

}
